package com.jxstyle.modular.controller;

import com.jxstyle.core.base.BaseController;
import com.jxstyle.core.common.page.PageInfo;
import com.jxstyle.modular.entity.Customer;
import com.jxstyle.modular.entity.Sale;
import com.jxstyle.modular.service.CustomerService;
import com.jxstyle.modular.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/sale")
public class SaleController extends BaseController {

	private final String prefix = "/sale";
	@Autowired
	private SaleService saleService;

	/**
	 * 列表
	 * @return
	 */
	@GetMapping(value = "")
	public String customerPage() {
		return prefix + "/list";
	}

	/**
	 *查询列表
	 * @param pageInfo
	 * @return
	 */
	@PostMapping(value ="" )
	@ResponseBody
	public PageInfo<Sale> page(PageInfo<Sale> pageInfo){
		PageInfo<Sale> page = saleService.page(pageInfo);
		return page;
	}

	/**
	 * 跳转到add.html
	 * @return
	 */
	@GetMapping(value = "/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 跳转到edit.html
	 * @param
	 * @param modelMap
	 * @return
	 */
	@GetMapping(value = "/edit/{id}")
	public String edit(@PathVariable int id, ModelMap modelMap) {
		modelMap.put("id", id);
		return prefix + "/edit";
	}

	/**
	 * 添加用户
	 * @param sale
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/add")
	public Boolean add(Sale sale) {
		saleService.save(sale);
		return true;
	}

	/**
	 * 修改用户
	 * @param sale
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/edit")
	public Boolean edit(Sale sale) {
		saleService.updateById(sale);
		return true;
	}

	/**
	 * 删除
	 * @param
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/delete/{id}")
	public Boolean delete(@PathVariable int id) {
		saleService.removeById(id);
		return true;
	}

	/**
	 * 通过id获取Sale对象
	 * @param
	 * @return
	 */
	@ResponseBody
	@GetMapping(value = "/get/{id}")
	public Sale get(@PathVariable int id) {
		Sale sale = saleService.getById(id);
		return sale;
	}




}
